<include file='Common:header' />

<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">

    <!-- #section:basics/sidebar -->
    <script>
        $(function(){
        $('#admin_rule_add').ajaxForm({
        beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
                success: complete, // 这是提交后的方法
                dataType: 'json'
        });
        function checkForm(){
        if ('' == $.trim($('#title').val())){
        layer.alert('名称不能为空', {icon: 6}, function(index){
        layer.close(index);
        $('#title').focus();
        });
        return false;
        }

        if ('' == $.trim($('#name').val())){
        layer.alert('控制器/方法不能为空', {icon: 6}, function(index){
        layer.close(index);
        $('#name').focus();
        });
        return false;
        }
        }
        function complete(data){
        if (data.status == 1){
        layer.alert(data.info, {icon: 6}, function(index){
        layer.close(index);
        window.location.href = data.url;
        });
        } else{
        alert(data.info);
        return false;
        }
        }

        });
        $(function(){
        $('#ruleorder').ajaxForm({
        success: complete, // 这是提交后的方法
                dataType: 'json'
        });
        function complete(data){
        if (data.status == 1){
        layer.alert(data.info, {icon: 6}, function(index){
        layer.close(index);
        window.location.href = data.url;
        });
        } else{
        layer.alert(data.info, {icon: 6}, function(index){
        layer.close(index);
        window.location.href = data.url;
        });
        }
        }
        });
    </script>
    <include file='Common:left' />
    <!-- /section:basics/sidebar -->

    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="row maintop">
                    <form class="form-horizontal" name="admin_rule_add" id="admin_rule_add" method="post" action="{:U('admin_rule_add')}">
                        <div class="col-xs-12 col-sm-12">
                            <small>状态：</small>
                            <small>
                                <select name="status">
                                    <option value="1">显示</option>
                                    <option value="0">不显示</option>
                                </select>
                            </small>
                            <small class="sl-left10">父级：</small>
                            <small>
                                <select name="pid">
                                    <option value="0">--默认顶级--</option>
                                    <foreach name="admin_rule" item="v">
                                        <option value="{$v.id}" style="margin-left:55px;">{$v.lefthtml}{$v.title}</option>
                                    </foreach>
                                </select>
                            </small>
                            <small class="sl-left10">名称：</small>
                            <small><input name="title" id="title" class="rule"/></small>
                            <small class="sl-left10">控/方：</small>
                            <small><input name="name" id="name" class="rule"/></small>
                            <small class="sl-left10">css：</small>
                            <small><input name="css" id="css" class="wh50"/></small>
                            <small class="sl-left10">排序：</small>
                            <small><input name="sort" id="sort" class="wh30" value="50"/></small>
                            <small>
                                <button class="btn btn-xs btn-danger ruleadd">
                                    添加权限
                                </button>
                            </small>
                        </div>
                    </form>
                    <div class="col-xs-12 col-sm-12 rule-top">
                        1、《控/方》：意思是 控制器/方法; 例如 Sys/sys_list<br />
                        2、css为控制左侧导航顶级栏目前图标样式，具体可查看FontAwesome图标CSS样式
                    </div>
                </div>

                <div class="row">
                    <div class="col-xs-12">
                        <div>
                            <form id="ruleorder" name="ruleorder" method="post" action="{:U('ruleorder')}" >
                                <table width="100%" class="table table-striped table-bordered table-hover" id="dynamic-table">
                                    <thead>
                                        <tr>
                                            <th width="6%">ID</th>
                                            <th width="19%">权限名称</th>
                                            <th width="22%">控制器/方法</th>
                                            <th width="15%">菜单状态</th>
                                            <th width="18%" style="border-right:#CCC solid 1px;">添加时间</th>
                                            <th width="11%" style="border-right:#CCC solid 1px;">排序</th>
                                            <th width="9%" style="border-right:#CCC solid 1px;">操作</th>
                                        </tr>
                                    </thead>

                                    <tbody>

                                    <foreach name="admin_rule" item="v">
                                        <tr>
                                            <td height="28">{$v.id}</td>
                                            <td style='padding-left:<if condition="$v.leftpin neq 0">{$v.leftpin}px</if>' >{$v.lefthtml}{$v.title}</td>
                                            <td>{$v.name}</td>
                                            <td>
                                        <if condition='$v[status] eq 1'>
                                            <a class="red" href="javascript:;" onclick="return stateyes({$v.id});" title="已开启">
                                                <div id="zt{$v.id}"><button class="btn btn-minier btn-yellow">显示状态</button></div>
                                            </a>
                                            <else/>
                                            <a class="red" href="javascript:;" onclick="return stateyes({$v.id});" title="已禁用">
                                                <div id="zt{$v.id}"><button class="btn btn-minier btn-danger">隐藏状态</button></div>
                                            </a>														</if>														</td>
                                        <td>{$v.addtime|date='Y-m-d',###}</td>
                                        <td><input name="{$v.id}" value=" {$v.sort}" class="list_order"/></td>
                                        <td>
                                            <div class="hidden-sm hidden-xs action-buttons">
                                                <a class="green" href="{:U('admin_rule_edit',array('id'=>$v['id']))}" title="修改">
                                                    <i class="ace-icon fa fa-pencil bigger-130"></i>							</a>
                                                <a class="red" href="javascript:;" onclick="return del({$v.id});" title="删除">
                                                    <i class="ace-icon fa fa-trash-o bigger-130"></i>							</a>						</div>														</td>
                                        </tr>
                                    </foreach>   
                                    <tr>
                                        <td colspan="8" align="left"><button type="submit"  id="btnorder" class="btn btn-white btn-yellow btn-sm">排序</button></td>
                                    </tr>
                                    </tbody>
                                </table>
                            </form>
                        </div>
                    </div>
                </div>

                <include file='Common:header_nav' />

                <script>
                    function del(id){
                    layer.confirm('你确定要删除吗？', {icon: 3}, function(index){
                    layer.close(index);
                    window.location.href = "__URL__/admin_rule_del/id/" + id + "";
                    });
                    }

                    function stateyes(val){
                    $.post('{:U("admin_rule_state")}',
                    {x:val},
                            function(data){
                            if (data.status){
                            if (data.info == '状态禁止'){
                            var a = '<button class="btn btn-minier btn-danger">隐藏状态</button>'
                                    $('#zt' + val).html(a);
                            layer.alert(data.info, {icon: 5});
                            } else{
                            var b = '<button class="btn btn-minier btn-yellow">显示状态</button>'
                                    $('#zt' + val).html(b);
                            layer.alert(data.info, {icon: 6});
                            }
                            }
                            });
                    return false;
                    }
                </script>
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    <include file='Common:footer' />

</div><!-- /.main-container -->
</body>
</html>
